<?php
	namespace Common\Logic;
	use Common\Model\DepartmentModel;
	class DepartmentLogic extends DepartmentModel{
		/*
		* Function:		getDepartmentList
		* Description:	部门管理列表
		* @param:		$page string 起始页
						$filter array 过滤数组
						$pageSize string 每页显示条数
		*/
		public function getDepartmentList($page=1,$filter = '',$pageSize=20){
			$conditon = $this->getDepartmentFilter($filter);
			return $this->where($conditon)->order('id desc')->limit(($page-1)*$pageSize,$pageSize)->select();
		}
		
		/*
		* Function:get:	getDepartmentFilter
		* Description:	部门管理列表搜索过滤项
		* @param:		$filter array 过滤数组
		*/
		public function getDepartmentFilter($filter = ''){
			$conditon = array();
			if(!empty($filter['name'])){
				$conditon['name'] = array('like','%'.$filter['name'].'%');
			}
			return $conditon;
		}
		
		/*
		* Function:get:	getDepartmentCount
		* Description:	部门管理列表总数
		* @param:		$filter array 过滤数组
		*/
		public function getDepartmentCount($filter = ''){
			$conditon = $this->getDepartmentFilter($filter);
			return $this->where($conditon)->count();
		}
		
		/*
		* Function:		addDepartment
		* Description:	增加部门管理
		* @param:		$data array 增加的数组
		*/
		public function addDepartment($data){
			return $this->add($data);
		}
		
		/*
		* Function:		getDepartmentInfo
		* Description:	获取部门管理信息 by row
		* @param:		$id int ID
		*/
		public function getDepartmentInfo($id){
			return $this->where(array('id'=>$id))->find();
		}
		
		/*
		* Function:		updateDepartment
		* Description:	更新部门管理
		* @param:		$data array 更新的数组
		*/
		public function updateDepartment($data){
			return $this->save($data);
		}
		
		/*
		* Function:		deleteDepartment
		* Description:	删除部门管理
		* @param:		$id int ID
		*/
		public function deleteDepartment($id){
			return $this->where(array('id'=>$id))->delete();
		}
		
		/*
		* Function:		getDepartmentAllList
		* Description:	部门列表
		*/
		public function getDepartmentAllList(){
			return $this->where(array('status'=>1))->select();
		}
	}
?>